<template>
  <div class="nested-zcgl-container">
    <div class="nested-zcgl-content">
      <el-tabs
        class="nested-tabs"
        v-model="tabName"
        @tab-click="handleTabsClick"
      >
        <!-- 1. 库存管理 -->
        <el-tab-pane class="nested-tab tab-first" label="库存管理" name="first">
          <!-- 搜索 -->
          <div class="search">
            <el-form
              :inline="true"
              :model="formInSearch"
              class="demo-form-inline"
            >
              <el-form-item label="">
                <el-select
                  @clear="getListForStock"
                  style="width: 121px"
                  v-model="formInSearch.type"
                  placeholder="全部分类"
                  clearable
                >
                  <el-option label="全部分类" value="all"></el-option>
                  <el-option label="桶装水分类" :value="1"></el-option>
                  <el-option label="xxx分类" value="fl"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-input
                  @clear="getListForStock"
                  clearable
                  style="width: 190px"
                  v-model="formInSearch.keywords"
                  placeholder="请输入商品名称/商品编号"
                ></el-input>
              </el-form-item>
              <el-form-item label="价格" style="margin-left: 35px">
                <el-input
                  @clear="getListForStock"
                  clearable
                  style="width: 110px"
                  type="number"
                  v-model.number="formInSearch.range1"
                ></el-input>
                -
                <el-input
                  @clear="getListForStock"
                  clearable
                  type="number"
                  style="width: 110px"
                  v-model.number="formInSearch.range2"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="getListForStock"
                  >搜索</el-button
                >
              </el-form-item>
              <el-form-item style="float: right">
                <el-button
                  @click="openBatchAdjustment"
                  style="background: #f0f0f0"
                  >批量调整</el-button
                >
              </el-form-item>
            </el-form>
          </div>

          <!-- table -->
          <!-- element-loading-background="rgba(0, 0, 0, 0.8)" -->
          <el-table
            v-loading="tableLoading"
            element-loading-text="拼命加载中"
            element-loading-spinner="el-icon-loading"
            :data="stockTableData"
            style="width: 100%"
            :header-cell-style="{
              backgroundColor: '#F0F0F0',
            }"
            :default-sort="{ prop: 'date', order: 'descending' }"
            row-key="goods_id"
            ref="multipleTable"
            @selection-change="batchAdjustmentSelection"
          >
            <el-table-column type="selection" width="100" align="center" />
            <el-table-column label="商品名称" width="340">
              <template slot-scope="scope">
                <p style="margin: 0 0 9px 0; color: #666666">
                  商品编号：
                  {{ scope.row.goods_sku }}
                </p>
                <div style="display: flex">
                  <img
                    style="width: 40px; height: 40px"
                    :src="configUrl + scope.row.goods_img"
                    alt="goods_img"
                  />
                  <p style="margin: 0 0 0 15px; width: 180px">
                    {{ scope.row.goods_name }}
                  </p>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="单价" align="center">
              <template slot-scope="scope">
                {{ "￥" + scope.row.price }}
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="stock_num"
              label="库存"
              sortable
            >
            </el-table-column>
            <el-table-column align="center" prop="sale_num" label="销量">
            </el-table-column>
            <el-table-column
              align="center"
              prop="create_time"
              label="创建时间"
              sortable
              width="220"
            >
            </el-table-column>
            <el-table-column align="center" label="操作" width="100">
              <template slot-scope="scope">
                <template>
                  <el-button
                    @click="openBatchAdjustment(scope.row)"
                    type="text"
                    size="small"
                    >调整库存</el-button
                  >
                  <el-button
                    @click="goKcmx(scope.row.goods_id)"
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    >库存明细</el-button
                  >
                </template>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>

        <!-- 2. 仓储订单管理 -->
        <el-tab-pane
          class="nested-tab tab-second"
          label="仓储订单管理"
          name="second"
        >
          <!-- 搜索 -->
          <div class="search">
            <el-form
              :inline="true"
              :model="formInSearch"
              class="demo-form-inline"
            >
              <el-form-item label="">
                <el-select
                  @clear="getListForBill"
                  style="width: 121px"
                  v-model="formInSearch.type"
                  placeholder="全部分类"
                  clearable
                >
                  <el-option label="总仓库存" :value="1"></el-option>
                  <el-option label="分仓库存" :value="2"></el-option>
                  <el-option label="网点库存" :value="3"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-select
                  @clear="getListForBill"
                  style="width: 121px"
                  v-model="formInSearch.bill_type"
                  placeholder="全部订单"
                  clearable
                >
                  <el-option label="全部订单" value=""></el-option>
                  <el-option label="入库单" :value="1"></el-option>
                  <el-option label="出库单" :value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-input
                  @clear="getListForBill"
                  clearable
                  style="width: 190px"
                  v-model="formInSearch.keywords"
                  placeholder="请输入商品名称/商品编号"
                ></el-input>
              </el-form-item>
              <el-form-item label="订单时间" style="margin-left: 35px">
                <el-date-picker
                  @change="getListForBill"
                  clearable
                  type="date"
                  v-model="formInSearch.start_date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                  style="width: 135px"
                ></el-date-picker>
                -
                <el-date-picker
                  @change="getListForBill"
                  value-format="yyyy-MM-dd"
                  v-model="formInSearch.end_date"
                  clearable
                  type="date"
                  placeholder="选择日期"
                  style="width: 135px"
                ></el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="getListForBill"
                  >搜索</el-button
                >
              </el-form-item>
            </el-form>
          </div>

          <!-- table -->
          <!-- element-loading-background="rgba(0, 0, 0, 0.8)" -->
          <el-table
            v-loading="tableLoading"
            element-loading-text="拼命加载中"
            element-loading-spinner="el-icon-loading"
            :data="billTableData"
            style="width: 100%"
            :header-cell-style="{
              backgroundColor: '#F0F0F0',
            }"
            :default-sort="{ prop: 'date', order: 'descending' }"
            row-key="bill_id"
          >
            <!-- expand -->
            <el-table-column type="expand">
              <template slot-scope="props">
                <el-table
                  :data="props.row.item"
                  style="width: 100%"
                  :header-cell-style="{
                    backgroundColor: '#F0F0F0',
                  }"
                  :default-sort="{ prop: 'date', order: 'descending' }"
                  row-key="goods_id"
                >
                  <el-table-column label="商品名称" width="340">
                    <template slot-scope="scope">
                      <p style="margin: 0 0 9px 0; color: #666666">
                        商品编号：
                        {{ scope.row.goods_sku }}
                      </p>
                      <div style="display: flex">
                        <img
                          style="width: 40px; height: 40px"
                          :src="configUrl + scope.row.goods_img"
                          alt="goods_img"
                        />
                        <p style="margin: 0 0 0 15px; width: 180px">
                          {{ scope.row.goods_name }}
                        </p>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="订单详情ID"
                    align="center"
                    prop="bill_detail_id"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="number"
                    label="数量"
                    sortable
                  >
                  </el-table-column>
                </el-table>
              </template>
            </el-table-column>

            <el-table-column align="center" prop="bill_code" label="仓储订单号">
            </el-table-column>
            <el-table-column align="center" prop="order_type" label="订单类型">
            </el-table-column>

            <el-table-column
              align="center"
              prop="class_name"
              label="组织机构名称"
            >
            </el-table-column>
            <el-table-column align="center" prop="status" label="状态">
            </el-table-column>
            <el-table-column
              align="center"
              prop="initiator_time"
              label="下单时间"
              sortable
              width="220"
            >
            </el-table-column>
            <el-table-column align="center" label="操作" width="100">
              <template slot-scope="scope">
                <template>
                  <el-button
                    v-if="
                      scope.row.order_type === '出库订单' &&
                      scope.row.status === '待确认'
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="confirmBill(scope.row.bill_id, 1)"
                    >接受订单</el-button
                  >
                  <el-button
                    v-if="
                      scope.row.order_type === '出库订单' &&
                      scope.row.status === '待发货'
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="confirmBill(scope.row.bill_id, 2)"
                    >确认发货</el-button
                  >
                  <el-button
                    v-if="
                      (scope.row.order_type === '出库订单' &&
                        scope.row.status === '待发货') ||
                      (scope.row.order_type === '入库订单' &&
                        ['待确认', '待发货'].includes(scope.row.status))
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="confirmBill(scope.row.bill_id, 3)"
                    >取消订单</el-button
                  >
                  <el-button
                    v-if="
                      scope.row.order_type === '出库订单' &&
                      scope.row.status === '待发货'
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="viewOrder(scope.row, 'centerDialogVisibleOut')"
                    >查看出库单</el-button
                  >
                  <el-button
                    v-if="
                      (scope.row.order_type === '出库订单' &&
                        scope.row.status === '已发货') ||
                      (scope.row.order_type === '入库订单' &&
                        scope.row.status === '已发货')
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="confirmBill(scope.row.bill_id, 4)"
                    >确认入库</el-button
                  >
                  <el-button
                    v-if="
                      (scope.row.order_type === '出库订单' &&
                        scope.row.status === '已发货') ||
                      (scope.row.order_type === '出库订单' &&
                        scope.row.status === '已完成')
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="viewOrder(scope.row, 'centerDialogVisibleDeliver')"
                    >查看发货单</el-button
                  >
                  <el-button
                    v-if="
                      scope.row.order_type === '入库订单' &&
                      scope.row.status === '已完成'
                    "
                    type="text"
                    size="small"
                    style="margin-left: 0"
                    @click="viewOrder(scope.row, 'centerDialogVisibleDetail')"
                    >查看入库单</el-button
                  >
                  <!-- @click="goDingdan" -->
                </template>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>

      <!-- 分页 -->
      <div class="fenye">
        <el-pagination
          @current-change="currentChange"
          background
          layout="pager, next, jumper"
          next-text="下一页"
          :total="oPagination.total"
          :page-count="oPagination.page_count"
          :pager-count="5"
        >
        </el-pagination>
      </div>

      <!-- 调整库存 dialog -->
      <el-dialog
        title="调整商品库存"
        :visible.sync="centerDialogVisible"
        width="60%"
        :show-close="false"
        center
        @close="cancelBatchAdjustment"
      >
        <el-table
          :data="batchAdjustmentData"
          style="padding: 0 20px"
          height="400"
          :default-sort="{ prop: 'date', order: 'descending' }"
        >
          <el-table-column label="商品名称" width="340">
            <template slot-scope="scope">
              <p style="margin: 0 0 9px 0; color: #666666">
                商品编号：
                {{ scope.row.goods_sku }}
              </p>
              <div style="display: flex">
                <img
                  style="width: 40px; height: 40px"
                  :src="configUrl + scope.row.goods_img"
                  alt="goods_img"
                />
                <p style="margin: 0 0 0 15px; width: 180px">
                  {{ scope.row.goods_name }}
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="old_stock_num" label="现有库存">
          </el-table-column>
          <el-table-column label="调整方式" width="180">
            <template slot-scope="scope">
              <el-radio-group
                v-model="scope.row.type"
                @change="changeStockNum(scope.row)"
              >
                <el-radio :label="1">增加</el-radio>
                <el-radio :label="-1">减少</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="调整数量" width="180">
            <template slot-scope="scope">
              <el-input
                @input="changeStockNum(scope.row)"
                type="number"
                v-model.number="scope.row.num"
                placeholder="请输入内容"
                style="width: 80px"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="stock_num" label="调整后库存">
          </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="confirmBatchAdjustment"
            >确认</el-button
          >
        </span>
      </el-dialog>

      <!-- 仓储订单出库单 dialog -->
      <el-dialog
        title="仓储订单出库单"
        :visible.sync="centerDialogVisibleOut"
        width="50%"
        top="0"
        center
      >
        <div class="pop2">
          <header>
            <p class="p3">订单信息</p>
            <div class="h-cont">
              <div class="hc-left">
                <p>仓储订单号：{{ orderData.bill_code || "-" }}</p>
                <p>下单人：{{ orderData.initiator_name || "-" }}</p>
                <p>订单接受人：{{ orderData.accept_name || "-" }}</p>
              </div>
              <div class="hc-model">
                <p>下单时间：{{ orderData.initiator_time || "-" }}</p>
                <p>下单机构：{{ orderData.class_name || "-" }}</p>
                <p>接受时间：{{ orderData.accept_time || "-" }}</p>
              </div>
              <div class="hc-right">
                <!-- <el-form ref="form" :model="form" label-width="80px">
                  <el-form-item label="下单备注: " style="margin-top: 15px">
                    <el-input
                      type="textarea"
                      v-model="form.desc"
                      :rows="3"
                    ></el-input>
                  </el-form-item> -->
                <!-- </el-form> -->
              </div>
            </div>
          </header>
          <el-table
            v-if="orderData.item.length > 0"
            :data="orderData.item"
            style="width: 100%"
            height="300"
            :default-sort="{ prop: 'date', order: 'descending' }"
          >
            <el-table-column label="商品名称" width="300">
              <template slot-scope="scope">
                <p style="margin: 0 0 9px 0; color: #666666">
                  商品编号：
                  {{ scope.row.goods_sku }}
                </p>
                <div style="display: flex">
                  <img
                    style="width: 40px; height: 40px"
                    :src="configUrl + scope.row.goods_img"
                    alt="goods_img"
                  />
                  <p style="margin: 0 0 0 15px; width: 180px">
                    {{ scope.row.goods_name }}
                  </p>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="cate_name" label="商品分类">
            </el-table-column>
            <el-table-column prop="number" label="数量" width="180">
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>

      <!-- 仓储订单发货单 dialog -->
      <el-dialog
        title="仓储订单发货单"
        :visible.sync="centerDialogVisibleDeliver"
        width="50%"
        top="0"
        center
      >
        <div class="pop2">
          <header>
            <p class="p3">订单信息</p>
            <div class="h-cont">
              <div class="hc-left">
                <p>仓储订单号：{{ orderData.bill_code || "-" }}</p>
                <p>下单人：{{ orderData.initiator_name || "-" }}</p>
                <p>订单接受人：{{ orderData.accept_name || "-" }}</p>
              </div>
              <div class="hc-model">
                <p>下单时间：{{ orderData.initiator_time || "-" }}</p>
                <p>下单机构：{{ orderData.class_name || "-" }}</p>
                <p>接受时间：{{ orderData.accept_time || "-" }}</p>
              </div>
              <div class="hc-right">
                <!-- <el-form ref="form" :model="form" label-width="80px">
                  <el-form-item label="下单备注: " style="margin-top: 15px">
                    <el-input
                      type="textarea"
                      v-model="form.desc"
                      :rows="3"
                    ></el-input>
                  </el-form-item> -->
                <!-- </el-form> -->
              </div>
            </div>

            <p class="p4">发货信息</p>
            <div class="h-cont">
              <div class="hc-left">
                <p>发货人：{{ orderData.send_name || "-" }}</p>
              </div>
              <div class="hc-model">
                <p>发货时间：{{ orderData.sender_time || "-" }}</p>
              </div>
              <div class="hc-right">
                <!-- <el-form ref="form" :model="form" label-width="80px">
                  <el-form-item label="下单备注: " style="margin-top: 15px">
                    <el-input
                      type="textarea"
                      v-model="form.desc"
                      :rows="3"
                    ></el-input>
                  </el-form-item>
                </el-form> -->
              </div>
            </div>
          </header>

          <el-table
            v-if="orderData.item.length > 0"
            :data="orderData.item"
            style="width: 100%"
            height="300"
            :default-sort="{ prop: 'date', order: 'descending' }"
          >
            <el-table-column label="商品名称" width="300">
              <template slot-scope="scope">
                <p style="margin: 0 0 9px 0; color: #666666">
                  商品编号：
                  {{ scope.row.goods_sku }}
                </p>
                <div style="display: flex">
                  <img
                    style="width: 40px; height: 40px"
                    :src="configUrl + scope.row.goods_img"
                    alt="goods_img"
                  />
                  <p style="margin: 0 0 0 15px; width: 180px">
                    {{ scope.row.goods_name }}
                  </p>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="cate_name" label="商品分类">
            </el-table-column>
            <el-table-column prop="number" label="数量" width="180">
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>

      <!-- 仓储订单详情 dialog -->
      <!-- 查看入库单 dialog -->
      <el-dialog
        title="仓储订单发货单"
        :visible.sync="centerDialogVisibleDetail"
        width="50%"
        top="0"
        center
      >
        <div class="pop2">
          <header>
            <p class="p3">订单信息</p>
            <div class="h-cont">
              <div class="hc-left">
                <p>仓储订单号：{{ orderData.bill_code || "-" }}</p>
                <p>下单人：{{ orderData.initiator_name || "-" }}</p>
                <p>订单接受人：{{ orderData.accept_name || "-" }}</p>
              </div>
              <div class="hc-model">
                <p>下单时间：{{ orderData.initiator_time || "-" }}</p>
                <p>下单机构：{{ orderData.class_name || "-" }}</p>
                <p>接受时间：{{ orderData.accept_time || "-" }}</p>
              </div>
              <div class="hc-right">
                <!-- <el-form ref="form" :model="form" label-width="80px">
                  <el-form-item label="下单备注: " style="margin-top: 15px">
                    <el-input
                      type="textarea"
                      v-model="form.desc"
                      :rows="3"
                    ></el-input>
                  </el-form-item> -->
                <!-- </el-form> -->
              </div>
            </div>

            <p class="p4">发货信息</p>
            <div class="h-cont">
              <div class="hc-left">
                <p>发货人：{{ orderData.send_name || "-" }}</p>
              </div>
              <div class="hc-model">
                <p>发货时间：{{ orderData.sender_time || "-" }}</p>
              </div>
              <div class="hc-right">
                <!-- <el-form ref="form" :model="form" label-width="80px">
                  <el-form-item label="下单备注: " style="margin-top: 15px">
                    <el-input
                      type="textarea"
                      v-model="form.desc"
                      :rows="3"
                    ></el-input>
                  </el-form-item>
                </el-form> -->
              </div>
            </div>

            <p class="p4">收货信息</p>
            <div class="h-cont">
              <div class="hc-left">
                <p>收货人：{{ orderData.recipient_name || "-" }}</p>
              </div>
              <div class="hc-model">
                <p>收货时间：{{ orderData.recipient_time || "-" }}</p>
              </div>
              <div class="hc-right"></div>
            </div>
          </header>

          <el-table
            v-if="orderData.item.length > 0"
            :data="orderData.item"
            style="width: 100%"
            height="300"
            :default-sort="{ prop: 'date', order: 'descending' }"
          >
            <el-table-column label="商品名称" width="300">
              <template slot-scope="scope">
                <p style="margin: 0 0 9px 0; color: #666666">
                  商品编号：
                  {{ scope.row.goods_sku }}
                </p>
                <div style="display: flex">
                  <img
                    style="width: 40px; height: 40px"
                    :src="configUrl + scope.row.goods_img"
                    alt="goods_img"
                  />
                  <p style="margin: 0 0 0 15px; width: 180px">
                    {{ scope.row.goods_name }}
                  </p>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="cate_name" label="商品分类">
            </el-table-column>
            <el-table-column prop="number" label="数量" width="180">
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {
  getStockList,
  setStockNumber,
  getBillList,
  getStockOrderInfo,
  setOrderStatus,
} from '@/api/nested'
export default {
  name: "nested-zcgl",
  data() {
    return {
      tabName: "first",
      tableLoading: false,
      oPagination: {
        total: 0,
        page_count: 0,
        page_num: 1,
        page_size: 10,
      },
      formInSearch: {
        type: 1,
        keywords: "",
        range1: "",
        range2: "",
        start_date: "",
        end_date: "",
        bill_type: "",
      },

      stockTableData: [],
      batchAdjustmentData: [],
      billTableData: [],

      // 调额
      centerDialogVisible: false,
      noCancelMessage: false,

      orderData: {
        item: []
      },
      // 仓储订单出库单
      centerDialogVisibleOut: false,
      // 查看发货单
      centerDialogVisibleDeliver: false,
      centerDialogVisibleDetail: false,

    }
  },
  computed: {
    ...mapGetters(['token'])
  },
  methods: {
    // 切换tab
    handleTabsClick(tab, event) {
      this.activeName = tab.name;
      this.formInSearch.type = 1;
      if (tab.name === "first") {
        this.getListForStock()
      } else {
        this.getListForBill()
      }
    },
    // 分页
    currentChange(val) {
      this.oPagination.page_num = val;
      this.getListForStock();
    },

    /********tab1**********/
    // tab1 - 库存明细
    goKcmx(val) {
      this.$router.push({
        path: "/nested/zongcangkucun", query: {
          id: val,
          type: 1
        }
      });
    },
    // 调整库存: 选中项用于批量调整库存
    batchAdjustmentSelection(val) {
      this.batchAdjustmentData = val;
    },
    // 调整库存: 是否开启
    openBatchAdjustment(row) {
      if (row.hasOwnProperty('goods_id')) {// row调用此方法
        this.batchAdjustmentData = [row];
      }
      if (this.batchAdjustmentData.length > 0) {
        this.batchAdjustmentData = this.batchAdjustmentData.map(item => {
          return {
            ...item,
            type: 1,
            num: 0,
            old_stock_num: item.stock_num
          }
        })
        this.centerDialogVisible = true;
        this.noCancelMessage = false;
      } else {
        this.$message({
          message: '没有选中需要调整的数据！',
          type: 'warning'
        });
      }
    },
    // 调整库存: dialog取消触发
    cancelBatchAdjustment() {
      this.batchAdjustmentData = [];
      this.$refs.multipleTable.clearSelection();
      if (this.noCancelMessage !== true) {
        this.$message({
          message: '取消批量调整！',
          type: 'warning'
        });
      }
    },
    // 调整库存: 数量改变重新map
    changeStockNum(val) {
      this.batchAdjustmentData = this.batchAdjustmentData.map(item => {
        if ((item.old_stock_num + item.type * item.num) < 0) {
          return {
            ...item,
            stock_num: 0,
            number: 0,
            // type: 1,
            num: item.old_stock_num,
          }
        } else {
          return {
            ...item,
            stock_num: item.old_stock_num + item.type * item.num,
            number: item.old_stock_num + item.type * item.num,
          }
        }

      })
    },
    // 调整库存：确定调整
    confirmBatchAdjustment() {
      this.batchAdjustmentData.forEach(item => {
        if (item.old_stock_num !== item.stock_num) {
          // 参数未知？？？
          setStockNumber({
            token: this.token,
            type: 1,
            // item	是	array	调整库存信息(二维数组)
            item: [{
              goods_id: item.goods_id,
              goods_name: item.goods_name,
              number: item.stock_num - item.old_stock_num
            }],
            // class_id: this.class_id,
            goods_id: item.goods_id,
            goods_name: item.goods_name,
            number: item.stock_num
          }).then(res => {
            // console.log(res)
            this.centerDialogVisible = false;
            this.noCancelMessage = true;
            this.getListForStock()
            this.$message({
              message: '批量修改成功！',
              type: 'success'
            });
          })
        }
      })
    },
    /********tab1**********/

    /********tab2**********/
    // 修改订单状态
    confirmBill(id, status) {
      setOrderStatus({
        token: this.token,
        bill_id: id,
        type: status
      }).then(res => {
        if (res.state) {
          this.getListForBill();
          this.$message({
            message: res.message,
            type: 'success'
          })
        }
      })
    },
    // tab2 - 订单详情
    goDingdan() {
      this.$router.push({ path: "/nested/orderdetail2" });
    },
    /********tab2**********/

    /********数据请求**********/

    getListForStock() {
      this.tableLoading = true;
      let obj = {
        token: this.token,
        type: 1,
        page_size: this.oPagination.page_size,
        page_num: this.oPagination.page_num,
        keywords: this.formInSearch.keywords,
      };
      if (this.formInSearch.range1 && this.formInSearch.range2 && this.formInSearch.range1 < this.formInSearch.range2) {
        obj.range_price = this.formInSearch.range1 + "-" + this.formInSearch.range2
      }
      getStockList(obj).then(res => {
        if (res.state) {
          this.tableLoading = false;

          const {
            all_data_num,
            all_page_num,
            current_page_num,
            current_page_size,
            list
          } = res.data
          this.stockTableData = list;
          this.oPagination.total = all_data_num;
          this.oPagination.page_count = all_page_num;
          this.oPagination.page_num = current_page_num;
          this.oPagination.page_size = current_page_size;//一页的显示的数量默认10
        } else {
          this.tableLoading = false;
          this.stockTableData = [];
          this.oPagination.total = 0;
        }
      }).catch(() => {
        this.tableLoading = false;
        this.stockTableData = [];
        this.oPagination.total = 0;
      })
    },
    getListForBill() {
      this.tableLoading = true;
      let obj = {
        token: this.token,
        type: 1,
        page_size: this.oPagination.page_size,
        page_num: this.oPagination.page_num,
      };
      if (this.formInSearch.keywords) {
        obj.keywords = this.formInSearch.keywords;
      }
      if (this.formInSearch.bill_type) {
        obj.bill_type = this.formInSearch.bill_type;
      }
      if (this.formInSearch.status) {
        obj.status = this.formInSearch.status;
      }
      if (this.formInSearch.start_date && this.formInSearch.end_date &&
        new Date(this.formInSearch.start_date).getTime() < new Date(this.formInSearch.end_date).getTime()) {
        obj.start_date = this.formInSearch.start_date;
        obj.end_date = this.formInSearch.end_date;
      }
      getBillList(obj).then(res => {
        if (res.state) {
          this.tableLoading = false;

          const {
            all_data_num,
            all_page_num,
            current_page_num,
            current_page_size,
            list
          } = res.data
          this.billTableData = list;
          this.oPagination.total = all_data_num;
          this.oPagination.page_count = all_page_num;
          this.oPagination.page_num = current_page_num;
          this.oPagination.page_size = current_page_size;//一页的显示的数量默认10
        } else {
          this.tableLoading = false;
          this.billTableData = [];
          this.oPagination.total = 0;
        }
      }).catch(() => {
        this.tableLoading = false;
        this.billTableData = [];
        this.oPagination.total = 0;
      })
    },
    // 获取仓储出入库订单信息(查看出库单,查看发货单,查看入库单)
    viewOrder(row, visiable) {
      getStockOrderInfo({
        token: this.token,
        bill_id: row.bill_id
      }).then(res => {
        if (res.state) {
          this[visiable] = true;
          this.orderData = res.data;
        }
      })
    }
  },
  mounted() {
    this.getListForStock()
  }
}
</script>

<style lang="scss" scoped>
.nested-zcgl-container {
  width: 98%;
  height: 100%;
  margin: 1%;
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 0px 2px 16px rgba(217, 217, 217, 0.44);
  .nested-zcgl-content {
    padding: 3% 8% 3% 3%;

    // .nested-tabs {
    // .nested-tab >>> .el-table--scrollable-y.el-table__body-wrapper{
    //     &::-webkit-scrollbar {
    //       /*滚动条整体样式*/
    //       width: 10px; /*高宽分别对应横竖滚动条的尺寸*/
    //       height: 1px;
    //     }
    // }
    // }
    .fenye {
      width: 100%;
      margin-top: 30px;
      display: flex;
      justify-content: flex-end;
    }

    .pop2 {
      header {
        width: 100%;
        overflow: hidden;
        .p3,
        .p4,
        .p5 {
          height: 40px;
          line-height: 40px;
          border-bottom: 1px solid #bbb;
          margin: 0;
        }
        .h-cont,
        .h-cont2 {
          display: flex;
          justify-content: space-between;
        }
        .h-cont2 {
          width: 51%;
        }
      }
    }
  }
}
</style>